package easy;

import org.junit.Test;

import java.util.Stack;

public class a20_有效的括号 {
    public boolean isValid(String s) {
        if(s.length()%2==1){
            return false;
        }
        Stack<Character> stack = new Stack<>();
        for(int i=0;i<s.length();i++){
            char c=s.charAt(i);
            if(c=='('){
                stack.push(')');
            }else if(c=='{'){
                stack.push('}');
            }else if(c=='['){
                stack.push(']');
            }else {
                if(stack.isEmpty()||c!=stack.pop()){
                    return false;
                }
            }
        }
        return stack.isEmpty();
    }
    @Test
    public void test(){
        String s="()";
        boolean valid = isValid(s);
        System.out.println(
                valid);
    }
}
